import {useState } from "react";
import './base.css'
export default function CountUse(props) {
    console.log(props,'获取兄弟组件的值')
    const obj = {
        name: 'maker',
        age: '36'
    }//定义一个对象
    const[count,addCount]=useState(0)
    //点击
    const clickButton=()=>{
        addCount(count+1)
    }
    const [newObj,changeObj]=useState({
        ...obj
    })
    //修改对象
    const exitObj=()=>{
        changeObj({
            ...obj,
            name:'Jack',
            age:'44'
        })
    }
    const Arr=['分类1','分类2','分类3']
    const [newArr,changeArr]=useState([...Arr])
    const exitArr=()=>{
        changeArr([...newArr,'分类4','分类5'],)}
    return (
        <div>
            <button onClick={clickButton}>当前的数据:{count}</button>
            <div onClick={exitObj} className='subTitle'>修改对象</div>
            <div>姓名:{newObj.name},年龄:{newObj.age}</div>
            <div onClick={exitArr} className='subTitle'>修改数组</div>
            <div>{newArr.map((item)=><div key={item}>{item}</div>)}</div>
            <div>第二个组件里:{props.name}</div>
        </div>
    )
}
